home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
frasr182.zip
/
PRINTER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-02
|
46KB
|
1,511 lines
/* Printer.c
* This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
* Simple screen printing functions for FRACTINT
* By Matt Saucier CIS: [72371,3101] 7/2/89
* "True-to-the-spirit" of FRACTINT, this code makes few checks that you
* have specified a valid resolution for the printer (just in case yours
* has more dots/line than the Standard HP and IBM/EPSON,
* (eg, Wide Carriage, etc.))
*
* PostScript support by Scott Taylor [72401,410] / (DGWM18A) 10/8/90
* For PostScript, use 'printer=PostScript/resolution' where resolution
* is ANY NUMBER between 10 and 600. Common values: 300,150,100,75.
* Default resolution for PostScript is 150 pixels/inch.
* At 200 DPI, a fractal that is 640x480 prints as a 3.2"x2.4" picture.
* PostScript printer names:
*
* PostScript/PS = Portrait printing
* PostScriptH/PostScriptL/PSH/PSL = Landscape printing
*
* This code supports printers attached to a LPTx (1-3) parallel port.
* It also now supports serial printers AFTER THEY ARE CONFIGURED AND
* WORKING WITH THE DOS MODE COMMAND, eg. MODE COM1:9600,n,8,1 (for HP)
* (NOW you can also configure the serial port with the comport= command)
* Printing calls are made directly to the BIOS for DOS can't handle fast
* transfer of data to the HP. (Or maybe visa-versa, HP can't handle the
* slow transfer of data from DOS)
*
* I just added direct port access for COM1 and COM2 **ONLY**. This method
* does a little more testing than BIOS, and may work (especially on
* serial printer sharing devices) where the old method doesn't. I noticed
* maybe a 5% speed increase at 9600 baud. These are selected in the
* printer=.../.../31 for COM1 or 32 for COM2.
*
* I also added direct parallel port access for LPT1 and LPT2 **ONLY**.
* This toggles the "INIT" line of the parallel port to reset the printer
* for each print session. It will also WAIT for a error / out of paper /
* not selected condition instead of quitting with an error.
*
* Supported Printers: Tested Ok:
* HP LaserJet
* LJ+,LJII MDS
* Toshiba PageLaser MDS (Set FRACTINT to use HP)
* IBM Graphics MDS
* EPSON
* Models? Untested.
* IBM LaserPrinter
* with PostScript SWT
* HP Plotter SWT
*
* Future support to include OKI 20 (color) printer, and just about
* any printer you request.
*
* Future modifications to include a more flexible, standard interface
* with the surrounding program, for easier portability to other
* programs.
*
* PostScript Styles:
* 0 Dot
* 1 Dot* [Smoother]
* 2 Inverted Dot
* 3 Ring
* 4 Inverted Ring
* 5 Triangle [45-45-90]
* 6 Triangle* [30-75-75]
* 7 Grid
* 8 Diamond
* 9 Line
* 10 Microwaves
* 11 Ellipse
* 12 RoundBox
* 13 Custom
* 14 Star
* 15 Random
* 16 Line* [Not much different]
*
* * Alternate style
*
*/
#include <stdlib.h>
#ifndef XFRACT
#include <bios.h>
#include <dos.h>
#include <io.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h> /*** for vsprintf prototype ***/
#ifndef XFRACT
#include <conio.h>
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <string.h>
#include <float.h> /* for pow() */
#include <math.h> /* " " */
#include "fractint.h"
#include "fractype.h"
#include "prototyp.h"
/* macros for near-space-saving purposes */
/* CAE 9211 changed these for BC++ */
#define PRINTER_PRINTF2(X,Y) {\
static char far tmp[] = X;\
Printer_printf(tmp,(Y));\
}
#define PRINTER_PRINTF3(X,Y,Z) {\
static char far tmp[] = X;\
Printer_printf(tmp,(Y),(Z));\
}
#define PRINTER_PRINTF4(X,Y,Z,W) {\
static char far tmp[] = X;\
Printer_printf(tmp,(Y),(Z),(W));\
}
/******** PROTOTYPES ********/
#ifndef XFRACT
static void Printer_printf(char far *fmt,...);
#else
static void Printer_printf();
#endif
static int _fastcall printer(int c);
static void _fastcall print_title(int,int,char *);
static void printer_reset();
static rleprolog(int x,int y);
static void _fastcall graphics_init(int,int,char *);
/******** EXTRN GLOBAL VARS ********/
extern int xdots,ydots, /* size of screen */
fractype; /* used for title block */
extern SEGTYPE extraseg; /* used for buffering */
extern BYTE dacbox[256][3]; /* for PostScript printing */
extern BYTE dstack[2][3][400];
extern char FormName[]; /* for Title block info */
extern char LName[]; /* for Title block info */
extern char IFSName[]; /* for Title block info */
extern char PrintName[]; /* Filename for print-to-file */
extern float finalaspectratio;
extern double xxmin,xxmax,xx3rd,
yymin,yymax,yy3rd,param[]; /* for Title block info */
extern int colors;
extern int dotmode;
extern unsigned int debugflag;
extern unsigned int far pj_patterns[];
extern BYTE far pj_reds[];
extern BYTE far pj_blues[];
extern BYTE far pj_greens[];
/******** GLOBALS ********/
int Printer_Resolution, /* 75,100,150,300 for HP; */
/* 60,120,240 for IBM; */
/* 90 or 180 for the PaintJet; */
/* 10-600 for PS */
/* 1-20 for Plotter */
LPTNumber, /* ==1,2,3 LPTx; or 11,12,13,14 for COM1-4 */
/* 21,22 for direct port access for LPT1-2 */
/* 31,32 for direct port access for COM1-2 */
Printer_Type, /* ==1 HP,
==2 IBM/EPSON,
==3 Epson color,
==4 HP PaintJet,
==5,6 PostScript,
==7 HP Plotter */
Printer_Titleblock, /* Print info about the fractal? */
Printer_Compress, /* PostScript only - rle encode output */
Printer_ColorXlat, /* PostScript only - invert colors */
Printer_SetScreen, /* PostScript only - reprogram halftone ? */
Printer_SFrequency, /* PostScript only - Halftone Frequency K */
Printer_SAngle, /* PostScript only - Halftone angle K */
Printer_SStyle, /* PostScript only - Halftone style K */
Printer_RFrequency, /* PostScript only - Halftone Frequency R */
Printer_RAngle, /* PostScript only - Halftone angle R */
Printer_RStyle, /* PostScript only - Halftone style R */
Printer_GFrequency, /* PostScript only - Halftone Frequency G */
Printer_GAngle, /* PostScript only - Halftone angle G */
Printer_GStyle, /* PostScript only - Halftone style G */
Printer_BFrequency, /* PostScript only - Halftone Frequency B */
Printer_BAngle, /* PostScript only - Halftone angle B */
Printer_BStyle, /* PostScript only - Halftone style B */
Print_To_File, /* Print to file toggle */
EPSFileType, /* EPSFileType -
1 = well-behaved,
2 = much less behaved,
3 = not well behaved */
Printer_CRLF, /* (0) CRLF (1) CR (2) LF */
ColorPS; /* (0) B&W (1) Color */
int pj_width;
double ci,ck;
static int repeat, item, count, repeatitem, itembuf[128], rlebitsperitem,
rlebitshift, bitspersample, rleitem, repeatcount, itemsperline, items,
bitsperitem, bitshift;
static void putitem(), rleputxelval(), rleflush(), rleputrest();
static int LPTn; /* printer number we're gonna use */
static FILE *PRFILE;
#define TONES 17 /* Number of PostScript halftone styles */
static char *HalfTone[TONES]= {
"D mul exch D mul add 1 exch sub",
"abs exch abs 2 copy add 1 gt {1 sub D mul exch 1 sub D mul add 1 sub} {D mul exch D mul add 1 exch sub} ifelse",
"D mul exch D mul add 1 sub",
"D mul exch D mul add 0.6 exch sub abs -0.5 mul",
"D mul exch D mul add 0.6 exch sub abs 0.5 mul",
"add 2 div",
"2 exch sub exch abs 2 mul sub 3 div",
"2 copy abs